<template>
  <div class="container">
    <el-dialog
      title="题目审核"
      :visible="toexamine"
      width="28%"
      @close="btnCancel"
    >
      <el-radio v-model="radio" label="1">通过</el-radio>
      <el-radio v-model="radio" label="2" style="margin-bottom : 18px"
        >拒绝</el-radio
      >
      <el-form :rules="rules" :model="ruleForm" ref="ruleForm">
        <el-form-item prop="textarea">
          <el-input
            style="padding : 5px 10px "
            type="textarea"
            :rows="2"
            placeholder="请输入审核意见"
            v-model="ruleForm.textarea"
          >
          </el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="btnCancel()">取 消</el-button>
        <el-button type="primary" @click="btnok()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { choiceCheck } from '@/api/hmmm/questions'

export default {
  inject: ['reload'],
  name: 'QuestionsCheck',
  data () {
    return {
      radio: '1', // 通过拒绝
      ruleForm: {
        textarea: '' // 审核意见
      },
      rules: {
        textarea: [
          { required: true, message: '请输入审核意见称', trigger: 'blur' }
        ]
      }
    }
  },
  props: {
    toexamine: {
      type: Boolean,
      default: false
    },
    id: {
      type: [String, Number],
      required: true
    }
  },
  methods: {
    // 点击关闭关闭弹窗
    btnCancel () {
      // 移出校验
      this.$refs.ruleForm.resetFields()
      this.$emit('update:toexamine', false)
    },
    // 点击确认
    async btnok () {
      await this.$refs.ruleForm.validate() // 校验表单
      try {
        choiceCheck({
          id: this.id,
          chkState: +this.radio,
          chkRemarks: this.ruleForm.textarea
        })
        // location.reload()
        // 在你需要的地方直接调用即可；
        this.reload()

        this.$message.success('审核成功')
        this.$emit('update:toexamine', false)
        this.$refs.ruleForm.resetFields()
      } catch (e) {
        this.$message.error('对不起系统繁忙，请稍后再试')
      }
    }
  }
}
</script>

<style scoped lang="scss"></style>
